<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标题">
              <a-input placeholder="请输入标题" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="分类">
<!--              <j-dict-select-tag placeholder="请选择一级分类" v-model="queryParam.firstType" dictCode="article_type"/>-->
              <a-cascader :options="options" placeholder="请选择分类" @change="onChange" :value="city"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="置顶">
              <j-dict-select-tag placeholder="请选择" v-model="queryParam.isTop" dictCode="is_top"/>
            </a-form-item>
          </a-col>
          <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="启用">
              <j-dict-select-tag placeholder="请选择" v-model="queryParam.isEnabled" dictCode="is_enabled"/>
            </a-form-item>
          </a-col>-->
          <!--<template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="二级分类">
                <j-dict-select-tag placeholder="请选择二级分类" v-model="queryParam.secondType" dictCode="notice"/>
              </a-form-item>
            </a-col>
          </template>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button @click="handleImport" type="primary" icon="import" v-has="'daorues'">导入ES</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('biz_platform_article')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="isEnabled_dictText" slot-scope="text,record">
<!--          <div v-html="text" style="color: #eb2f96" v-if="record.isEnabled == 0"></div>-->
<!--          <div v-html="text" v-else></div>-->
          <a-popconfirm  :title="record.isEnabled == 1?'确定禁用吗?':'确定启用吗?'" @confirm="() => handleQidong(record.id)">
            <a-switch checked-children="正常" class="ssss" un-checked-children="停用" disabled :checked="record.isEnabled == 1?true:false" />
          </a-popconfirm>
        </template>
        <template slot="isTop_dictText" slot-scope="text,record">
<!--          <div v-html="text" v-if="record.isTop == 1" style="color: #ff8000"></div>-->
<!--          <div v-html="text" v-else></div>-->
          <a-popconfirm  :title="record.isTop == 1?'取消置顶吗?':'确定置顶吗?'" @confirm="() => handleZhiding(record.id)">
            <a-switch checked-children="置顶" class="ssss1" un-checked-children="普通" disabled :checked="record.isTop == 1?true:false" />
          </a-popconfirm>
        </template>
        <template slot="secondType_dictText" slot-scope="text">
          <div>{{returnSecondType(text)}}</div>
        </template>
        <!--<template slot="isTop" slot-scope="text">
          <div v-html="text"></div>
        </template>-->
        <template slot="state_dictText" slot-scope="text,record">
          <div v-html="text" v-if="record.state == 0" style="color: #2eabff"></div>
          <div v-html="text" v-else-if="record.state == -1" style="color: #eb2f96"></div>
          <div v-html="text" v-else style="color: #00DB00"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <span v-if="record.state==-1">
            <a @click="handleAudit(record.id)">被拒原因</a>
            <a-divider type="vertical" />
          </span>
          <span v-if="record.state == 0">
            <a @click="handleShenhe(record)">审核</a>
            <a-divider type="vertical" />
          </span>
          <!--<span>
            <a-popconfirm title="确定停用吗?" v-if="record.isEnabled == 1" @confirm="() => handleQidong(record.id)">
              <a>停用</a>
            </a-popconfirm>
            <a-popconfirm title="确定启用吗?" v-else @confirm="() => handleQidong(record.id)">
              <a>启用</a>
            </a-popconfirm>
            <a-divider type="vertical" />
          </span>
          <span>
            <a-popconfirm title="确定置顶吗?" v-if="record.isTop == 0" @confirm="() => handleZhiding(record.id)">
              <a>置顶</a>
            </a-popconfirm>
            <a-popconfirm title="确定取消置顶吗?" v-else @confirm="() => handleZhiding(record.id)">
              <a>取消置顶</a>
            </a-popconfirm>
            <a-divider type="vertical" />
          </span>-->
          <span>
            <a @click="handleEdit(record)">编辑</a>
            <a-divider type="vertical" />
          </span>
          <span>
            <a @click="handleDetail(record)">详情</a>
          </span>
          <!--<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item >
                <a @click="handleEdit(record)">编辑</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <biz-platform-article-modal ref="modalForm" @ok="modalFormOk"></biz-platform-article-modal>
    <ShenheModal ref="shenheModal" @ok="modalFormOk"></ShenheModal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import BizPlatformArticleModal from './modules/BizPlatformArticleModal'
  import ShenheModal from './modules/ShenheModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import { putAction,getAction } from '../../api/manage'

  export default {
    name: 'BizPlatformArticleList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      BizPlatformArticleModal,
      ShenheModal
    },
    data () {
      return {
        description: 'biz_platform_article管理页面',
        city:[],
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'标题',
            align:"center",
            dataIndex: 'title'
          },
          /*{
            title:'内容',
            align:"center",
            dataIndex: 'content',
            scopedSlots: {customRender: 'htmlSlot'}
          },*/
          {
            title:'一级分类',
            align:"center",
            dataIndex: 'firstType_dictText'
          },
          {
            title:'二级分类',
            align:"center",
            dataIndex: 'secondType',
            scopedSlots: {customRender: 'secondType_dictText'}
          },
          {
            title:'来源',
            align:"center",
            dataIndex: 'source'
          },
          {
            title:'阅读量',
            align:"center",
            dataIndex: 'readingCount'
          },

          {
            title:'是否启用',
            align:"center",
            dataIndex: 'isEnabled_dictText',
            scopedSlots: {customRender: 'isEnabled_dictText'}
          },
          {
            title:'是否顶置',
            align:"center",
            dataIndex: 'isTop_dictText',
            scopedSlots: {customRender: 'isTop_dictText'}
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'state_dictText',
            scopedSlots: { customRender: 'state_dictText' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
          /*{
            title:'创建人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'修改人',
            align:"center",
            dataIndex: 'updateBy'
          },
          {
            title:'修改时间',
            align:"center",
            dataIndex: 'updateTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },*/

        ],
        options: [
          {
            value: 'notice',
            label: '公告',
            children: [
              {
                value: 'system',
                label: '系统公告',
              },
              {
                value: 'listing',
                label: '挂牌公告',
              },
              {
                value: 'establishing',
                label: '成立公告',
              },
              {
                value: 'cashing',
                label: '兑付公告',
              },
            ],
          },
          {
            value: 'news',
            label: '新闻',
            children: [
              {
                value: 'news',
                label: '新闻',
              },
            ],
          },
          {
            value: 'policies_regulations',
            label: '政策法规',
            children: [
              {
                value: 'nation_policies_regulations',
                label: '国家政策法规',
              },
              {
                value: 'trading_rules',
                label: '交易规则',
              },
              {
                value: 'selfdiscipline_declare',
                label: '自律声明',
              },
            ],
          },
        ],
        url: {
          list: "/platformarticle/bizPlatformArticle/list",
          delete: "/platformarticle/bizPlatformArticle/delete",
          deleteBatch: "/platformarticle/bizPlatformArticle/deleteBatch",
          exportXlsUrl: "/platformarticle/bizPlatformArticle/exportXls",
          importExcelUrl: "platformarticle/bizPlatformArticle/importExcel",
          isAvailable:"/platformarticle/bizPlatformArticle/isAvailable",//启用停用
          isTop:"/platformarticle/bizPlatformArticle/isTop",//置顶
          getAuditDetail:"/platformarticle/bizPlatformArticle/getAuditDetail",
          syncData:"/platformarticle/bizPlatformArticle/syncData" //导入ES

        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      //审核
      handleShenhe(record){
        this.$refs.shenheModal.edit(record);
        this.$refs.shenheModal.title = "审核";
        this.$refs.shenheModal.disableSubmit = true;
      },
      //启用==停用
      handleQidong(id){
        this.loading = true
        putAction(this.url.isAvailable,{id:id}).then((res)=>{
          if (res.success){
            this.$message.success(res.message)
            this.loadData()
          }else {
            this.$message.error(res.message)
          }
        }).finally(()=>{
          this.loading = false
        })
      },
      //置顶
      handleZhiding(id){
        this.loading = true
        putAction(this.url.isTop,{id:id}).then((res)=>{
          if (res.success){
            this.$message.success(res.message)
            this.loadData()
          }else {
            this.$message.error(res.message)
          }
        }).finally(()=>{
          this.loading = false
        })
      },
      //被拒原因
      handleAudit(id){
        getAction(this.url.getAuditDetail,{id:id}).then((res)=>{
          console.log(res)
          if (res.success){
            this.$error({
              title: '拒审原因',
              content: res.result.remark,
            })
          }else {
            this.$message.error(res.message)
          }

        })
      },
      returnSecondType(text){
        for (let textElement of this.options) {
          for (let textElementElement of textElement.children) {
            if (text==textElementElement.value){
              return textElementElement.label
            }
          }

        }
      },
      onChange(value,selectedOption) {
        console.log(value);
        // console.log(selectedOption);
        this.city = value
        this.queryParam.secondType = value[1]
      },

      //导入ES
      handleImport(){
        getAction(this.url.syncData).then((res)=>{
          console.log(res)
          if (res.success){
            this.$message.success('成功导入'+res.result+'条')
          }
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .ant-switch-disabled{
    cursor: pointer;
    opacity: 1;
  }
  .ssss{
    cursor: pointer !important;
  }
  .ssss1{
    cursor: pointer !important;
  }
  .ssss .ant-switch{
    background-color: rgb(255, 73, 73);
  }
  .ssss1 .ant-switch{
    background-color: rgba(0,0,0,0.3) !important;
  }
  .ant-switch-checked{
    background-color: #1890FF !important;
  }
  .ssss1 .ant-switch-checked{
    background-color: #1890FF !important;
  }
</style>